package db;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.*;
import java.util.HashMap;

public class Row {

    //Package scope members 
    Object[] values;
	String[] names;
	HashMap<String,Integer> indices;
	
    //Package scope constructor 
	Row(HashMap<String,Integer> indices,String[] names)
	{
		this.indices=indices;
		this.values=new Object[names.length];
		this.names=names;
	}
	
	public Class<?> getFieldType(int index)
	{
		return values[index].getClass();
	}
	public Class<?> getFieldClass(String name)
	{
		return getFieldType(indices.get(name));
	}
	public String getFieldName(int index)
	{
		return names[index];
	}

	public Boolean getBoolean(int index)
    {
        return (Boolean)values[index];
    }
    public Boolean getBoolean(String name)
    {
        return (Boolean)values[indices.get(name)];
    }
    public Character getCharacter(int index)
    {
        return (Character)values[index];
    }
    public Character getCharacter(String name)
    {
        return (Character)values[indices.get(name)];
    }

    public Date getDate(int index)
    {
        return (Date)values[index];
    }
    public Date getDate(String name)
    {
        return (Date)values[indices.get(name)];
    }
    
    public Timestamp getTimestamp(int index)
    {
        return (Timestamp)values[index];
    }
    public Timestamp getTimestamp(String name)
    {
        return (Timestamp)values[indices.get(name)];
    }
    
    public BigDecimal getBigDecimal(int index)
    {
        return (BigDecimal)values[index];
    }
    public BigDecimal getBigDecimal(String name)
    {
        return (BigDecimal)values[indices.get(name)];
    }

    public BigInteger getBigInteger(int index)
    {
        return (BigInteger)values[index];
    }
    public BigInteger getBigInteger(String name)
    {
        return (BigInteger)values[indices.get(name)];
    }
    
    public Double getDouble(int index)
    {
        return (Double)values[index];
    }
    public Double getDouble(String name)
    {
        return (Double)values[indices.get(name)];
    }
    
    public Float getFloat(int index)
    {
        return (Float)values[index];
    }
    public Float getFloat(String name)
    {
        return (Float)values[indices.get(name)];
    }

    public Byte getByte(int index)
    {
        return (Byte)values[index];
    }
    public Byte getByte(String name)
    {
        return (Byte)values[indices.get(name)];
    }
    
    public Short getShort(int index)
    {
        return (Short)values[index];
    }
    public Short getShort(String name)
    {
        return (Short)values[indices.get(name)];
    }
    
    public Integer getInteger(int index)
    {
        return (Integer)values[index];
    }
    public Integer getInteger(String name)
    {
        return (Integer)values[indices.get(name)];
    }
    
    public Long getLong(int index)
    {
        return (Long)values[index];
    }
    public Long getLong(String name)
    {
        return (Long)values[indices.get(name)];
    }
    
    public String getString(int index)
    {
        return (String)values[index];
    }
    public String getString(String name)
    {
        return (String)values[indices.get(name)];
    }
    
    public Object getValue(int index)
    {
        return values[index];
    }
    public Object getValue(String name)
    {
        return values[indices.get(name)];
    }
    public boolean IsNull(int index)
    {
        return values[index]==null;
    }
    public boolean IsNull(String name)
    {
        return values[indices.get(name)]==null;
    }
    public int getNumColumns()
    {
        return values.length;
    }
}
